package com.bye.controller;

import com.bye.annotation.Login;
import com.bye.dto.ManagerDto;
import com.bye.dto.MenuDto;
import com.bye.exception.MyException;
import com.bye.service.ManagerService;
import com.bye.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/manager")
public class ManagerController {
    @Autowired
    private ManagerService managerService;


    @RequestMapping("/login")
    public Result login(@RequestBody ManagerDto managerDto) {
        System.out.println(managerDto);
        try {
            String token = managerService.login(managerDto);

            return Result.success().put("token",token);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    @Login
    @RequestMapping("/getMenu")
    public Result getMenu( ManagerDto managerDto) {
        //已经给方法中的形参赋值
        try {
            List<MenuDto> menuDtoList = managerService.selectMenuById(managerDto.getId());
            return Result.success().put("user",managerDto).put("menuList",menuDtoList);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage());
        }

    }
}
